<?php
namespace app\controller\admin;

use app\BaseController;
use app\model\CustomerModel;
use think\facade\Request;
class Customer extends BaseController
{

    public function index(){


        // global $_GPC;
        $filter['name'] = Request::param('name');
        $filter['status'] = Request::param('status');
        $filter['telephone'] = Request::param('telephone');
        $filter['customer_group_id'] = Request::param('customer_group_id');
        // if( isset( $_GPC['name']) ){
        //     $filter['name'] = $_GPC['name'];
        // }
        // if( isset($_GPC['status']) ){
        //     $filter['status'] = $_GPC['status'];
        // }
        // if( isset($_GPC['telephone']) ){
        //     $filter['telephone'] = $_GPC['telephone'];
        // }

        // if( isset($_GPC['customer_group_id']) ){
        //     $filter['customer_group_id'] = $_GPC['customer_group_id'];
        // }

        $res = CustomerModel::get_list( $filter );

        return json( $res );

    }

    
    
    public function single(){

        $customer_id = $id = Request::param('id');
        $single = CustomerModel::single( $customer_id );

        return json( $single );
    }

    public function edit(){

        $id = $_GET['id'];

        $data = [
            'customer_group_id'=> Request::param('customer_group_id'),
            'remark'=> Request::param('remark')?:''
        ];

        $ret = CustomerModel::edit( $id, $data );
        $res = [
            'status'=>0,
            'ret'=>$ret
        ];

        return json( $res );

    }


}